/*
    WdgCore.js
    Copyright (C) 2010-2011, Donald W. Griffin
    All Rights Reserved
*/
Ext.namespace("Wdg");

Ext.apply(Wdg, {
    reg : function (T) {
        var t = T.prototype.xtype;
        Ext.reg(t, T);
    },

    regLayout : function (T) {
        var t = T.prototype.type;
        Ext.Container.LAYOUTS[t] = T;
    },

    zeroPad : function (v, n) {
        var s = String(v);
        while (s.length < n)
            s = '0' + s;
        return s;
    }
});

Ext.applyIf(Function.prototype, function () {

    var slice = Array.prototype.slice;

    function bindArgs (fn, obj, args) {
        return function () {
            var a = arguments.length ? args.concat(slice.call(arguments, 0)) : args;
            return fn.apply(obj, a);
        }
    }

    function bindObj (fn, obj) {
        return function () {
            return fn.apply(obj, arguments);
        };
    }

    return {
        bind: function (obj) {
            if (arguments.length === 1)
                return bindObj(this, obj);

            return bindArgs(this, obj, slice.call(arguments, 1));
        }
    };
}());
